#coding=utf-8

from tforms import validators
from tforms.fields import TextField, PasswordField
from tforms.forms import TornadoForm as Form
from tforms.validators import ValidationError

class RegisterForm(Form):
    username = TextField(
        'Username', [
            validators.Required(),
            validators.Length(min=4, max=16),
            validators.Regexp(
                '[a-zA-Z0-9-]',
                message=u'Username can only contain English characters and digits',
            ),
        ],
        description=u'Username can only contain English characters and digits'
    )
    password = PasswordField(
        'Password', [
            validators.Required(),
            validators.Length(min=6),
        ],
        description='Number must be greater than %(min)s.'
    )
    password2 = PasswordField(
        'Confirm', [
            validators.Required(),
            validators.Length(min=6),
        ],
        description='Number must be greater than %(min)s.'
    )
    realname = TextField(
        'RealName', [
            validators.Required(),
        ],        
    )

    def validate_password2(form, field):
        if field.data != form.password.data:
            raise ValidationError("Password not match.")
